<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var arr = [1,6,4,3,-9,8]
        var maxN = arr[0], maxI, minN = arr[0], minI
        for (var i = 0; i < arr.length; i ++) {
            if (arr[i] > maxN) {
                maxN = arr[i]
                maxI = i
            }
            if (arr[i] < minN) {
                minN = arr[i]
                minI = i
            }
        }
        console.log(`最大值为${maxN}, 下标为${maxI}；最小值为${minN}，下标为${minI}`)
    </script>
</body>
</html>